<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta charset="UTF-8">
    <script src="js/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <title>Vue demo 07 计算属性</title>
</head>
<body>
<div id="demo">
    <p>原数据{{message}}</p>
    <p>反转后的数据{{resversedMessage}}</p>
    <button @click="add()">补充货物+1</button>
    <div>总价为: {{price}}</div>
</div>

<p>=============================================</p>

<div id="demo2">
    <div id="app1">{{text}}</div>
    <div id="app2">{{reverseText}}</div>
</div>

</body>
<script>
    let vm = new Vue({
        el: '#demo',
        data: {
            message: 'abcdefg',
            package: {
                count: 5,
                price: 5
            },
        },
        computed: {
            resversedMessage: function () {
                return this.message.split('').reverse().join('')
            },
            price: function () {
                return this.package.count * this.package.price
            }
        },
        methods: {
            add: function () {
                this.package.count++
            }
        }
    })
</script>

<script>

    let app1 = new Vue({
        el: '#app1',
        data: {
            text: 'computed'
        }
    });
    let app2 = new Vue({
        el: '#app2',
        computed: {
            reverseText: function () {
                return app1.text.split('').reverse().join('')
            }
        }
    });
</script>
</html>